时间计时器,学VB入门实例 Option Explicit
Private A As Integer, SS As Double, T1 As Date, T2 As Date
Private Sub Form_Load() '软件打开时初始化
A = 0: SS = 0: T1 = Now(): T2 = Now()
End Sub
Private Sub Timer1_Timer() '刷新显示
Label5.Caption = Format(Now, "Long Time") '显示当时时间
If A = 1 Then '允许计时
SS = DateDiff("s", T1, Now)
Label2.Caption = SS Mod 60
Label3.Caption = Int((SS Mod 3600) / 60)
Label4.Caption = Int(SS / 3600)
End If
End Sub
Private Sub Command1_Click() '开始暂停
If A = 1 Then '按下暂停
A = 2: T2 = Now()
Else '按下开始或继续
A = 1: T1 = DateAdd("S", -DateDiff("s", T1, T2), Now())
End If
End Sub
Private Sub Command2_Click() '停止清零
Label2.Caption = "0": Label3.Caption = "0": Label4.Caption = "0"
A = 0: T1 = Now(): T2 = Now()
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) '关闭软件时
End Sub
评论